package com.example.demo.controller;

import com.example.demo.bean.PageBean;
import com.example.demo.bean.product;
import com.example.demo.service.IFirstService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Controller
public class FirstController {

    private final static Logger logger = LoggerFactory.getLogger(FirstController.class);

    @Autowired
    IFirstService iFirstService;

    @RequestMapping("/add")
    public void toAdd() {
        product p = new product();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
        String data = simpleDateFormat.format(new Date());
        p.setpName(data);
        iFirstService.save(p);
    }

    @RequestMapping("/find")
    @ResponseBody
    public Map find(int currentPage, int MaxSize) {
        Map result = new HashMap();
        PageBean pageBean = iFirstService.find(currentPage, MaxSize);
        result.put("result", pageBean);
        return result;
    }



    @RequestMapping("/findone")
    public void findone() {
       product p =  iFirstService.findone();
       logger.info(p.toString());
    }
}
